<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学号+姓名+家乡美食</title>
    <style>
        body {
            font-family: "Microsoft YaHei", sans-serif;
            padding: 20px;
            background: #fff;
        }
        .form-container {
            max-width: 600px;
            margin: 0 auto;
            padding: 20px;
            background: #F1F8E9;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        .form-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 8px;
            color: #2E7D32;
            font-weight: bold;
        }
        input[type="text"],
        input[type="password"],
        select {
            width: 100%;
            padding: 8px;
            border: 1px solid #4CAF50;
            border-radius: 4px;
            font-size: 16px;
        }
        .radio-group,
        .checkbox-group {
            margin: 10px 0;
        }
        .radio-group label,
        .checkbox-group label {
            display: inline-block;
            margin-right: 15px;
            font-weight: normal;
        }
        button {
            background: #4CAF50;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            margin-right: 10px;
        }
        button:hover {
            background: #2E7D32;
        }
        .error {
            color: #f44336;
            font-size: 14px;
            margin-top: 5px;
            display: none;
        }
    </style>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function() {
            $('#foodForm').on('submit', function(e) {
                e.preventDefault();
                
                // 验证姓名
                if ($('#name').val().trim() === '') {
                    $('#nameError').show();
                    return;
                }
                
                // 验证密码
                if ($('#password').val().length < 6) {
                    $('#passwordError').show();
                    return;
                }
                
                // 验证是否选择性别
                if (!$('input[name="gender"]:checked').length) {
                    $('#genderError').show();
                    return;
                }
                
                // 验证是否选择美食
                if (!$('input[name="foods"]:checked').length) {
                    $('#foodsError').show();
                    return;
                }
                
                // 收集表单数据
                let formData = {
                    name: $('#name').val(),
                    gender: $('input[name="gender"]:checked').val(),
                    foods: $('input[name="foods"]:checked').map(function() {
                        return this.value;
                    }).get(),
                    cuisine: $('#cuisine').val()
                };
                
                // 显示结果
                alert('表单提交成功！\n' + 
                      '姓名：' + formData.name + '\n' +
                      '性别：' + formData.gender + '\n' +
                      '喜欢的美食：' + formData.foods.join('、') + '\n' +
                      '所属菜系：' + formData.cuisine);
            });
            
            // 重置错误提示
            $('input, select').on('input change', function() {
                $('.error').hide();
            });
        });
    </script>
</head>
<body>
    <div class="form-container">
        <h2>家乡美食调查表</h2>
        <form id="foodForm">
            <div class="form-group">
                <label for="name">姓名：</label>
                <input type="text" id="name" name="name">
                <div id="nameError" class="error">请输入姓名</div>
            </div>
            
            <div class="form-group">
                <label for="password">密码：</label>
                <input type="password" id="password" name="password">
                <div id="passwordError" class="error">密码长度至少6位</div>
            </div>
            
            <div class="form-group">
                <label>性别：</label>
                <div class="radio-group">
                    <label><input type="radio" name="gender" value="男"> 男</label>
                    <label><input type="radio" name="gender" value="女"> 女</label>
                </div>
                <div id="genderError" class="error">请选择性别</div>
            </div>
            
            <div class="form-group">
                <label>喜欢的美食：</label>
                <div class="checkbox-group">
                    <label><input type="checkbox" name="foods" value="特色小吃"> 特色小吃</label>
                    <label><input type="checkbox" name="foods" value="传统点心"> 传统点心</label>
                    <label><input type="checkbox" name="foods" value="地方特产"> 地方特产</label>
                    <label><input type="checkbox" name="foods" value="农家菜"> 农家菜</label>
                </div>
                <div id="foodsError" class="error">请至少选择一个美食</div>
            </div>
            
            <div class="form-group">
                <label for="cuisine">所属菜系：</label>
                <select id="cuisine" name="cuisine">
                    <option value="">请选择</option>
                    <option value="川菜">川菜</option>
                    <option value="粤菜">粤菜</option>
                    <option value="苏菜">苏菜</option>
                    <option value="鲁菜">鲁菜</option>
                    <option value="其他">其他</option>
                </select>
            </div>
            
            <div class="form-group">
                <button type="submit">提交</button>
                <button type="reset">重置</button>
            </div>
        </form>
    </div>
</body>
</html> 